#ifndef CONNECTDIALOG_H
#define CONNECTDIALOG_H
#include "DbConnection.h"

class QWidget;
class QDialog;
class QLabel;
class QPushButton;
class QComboBox;
class QLineEdit;
struct unit{
    QString name;
    DbConnection::Parameters params;
    QStringList users;
};
class ConnectDialog: public  QDialog
{
    Q_OBJECT
public:
    ConnectDialog(QWidget* parent, const QList<unit>&units);
    bool login();
    void setUsrName(const QStringList &users);   
    void setUsrName(const QString &userName);
    void setCurUser(const QString &userName);
    void setUnitName(const QList<unit> &units);
    int index() const;
    DbConnection* db();
private:
    QPushButton *okButton;
    QPushButton *cancelButton;
    QLabel *usrLabel;
    QLabel *pswLabel;
    QComboBox *usrBox;
    QLineEdit *psw;
    DbConnection *auth;
    QList<unit> m_units;
private slots:
    void okButttonEnabled();
    void onUnitChanged(const int&Index);
    void onUserChange();
    void cancelButtonCkick();
    void stateChange(int state);
};
#endif // CONNECTDIALOG_H
